<?php
/**
 *  单页信息控制器
 */
namespace app\admin\controller;

use app\common\controller\AdminBase;
use app\admin\model\Pageinfo;

class Webpageinfo extends AdminBase
{
    protected function _initialize()
    {
        parent::_initialize();
    }
    /**
     * 单页信息
     */
    public function pageinfo()
    {
        $nid = 1;
        $m = new Pageinfo;
        $rows = $m::get(['nid'=>$nid]);//->toArray();
        $rows && $rows = json_decode($rows,true);   //rows为空时，->toArray方法报错
        if($this->request->isAjax()){
            $data = input('post.'); $data['nid'] = $nid;    $json_arr_cn = [];
            $data['title_cn'] = '单页信息';
            if($data['photo_imgList']){
                foreach($data['photo_imgList'] as $k=>$v){
                    $v && $json_arr_cn[] = ['img'=>$v,'tit'=>$data['tit_imgList'][$k],'sort'=>$data['sort_imgList'][$k]?:0];
                }
                array_multisort(array_column($json_arr_cn,'sort'),SORT_DESC,$json_arr_cn);
            }
            $data['json_arr_cn'] = json_encode($json_arr_cn,JSON_UNESCAPED_UNICODE);
            !$rows && $data['add_time'] = date('Y-m-d H:i:s');

            return $m->_save1($data,$rows?true:false);
        }
        $rows['json_arr_cn'] = json_decode($rows['json_arr_cn'],true);
        return $this->fetch('pageinfo',['rows'=>$rows]);
    }
}